package com.old.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.old.dto.VideoCommentDTO;
import com.old.dto.VideoCommentQueryDTO;
import com.old.entity.VideoComment;
import com.old.mapper.VideoCommentMapper;
import com.old.result.PageBean;
import com.old.service.VideCommentService;
import com.old.vo.VideoCommentVO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@RequiredArgsConstructor
public class VideoCommentImpl  implements VideCommentService {

    private final VideoCommentMapper videoCommentMapper;
    /**
     * 添加戏曲评论
     * @param videoCommentDTO
     */
    @Transactional
    public void addComment(VideoCommentDTO videoCommentDTO) {
        VideoComment videoComment=new VideoComment();
        BeanUtils.copyProperties(videoCommentDTO, videoComment);
        videoCommentMapper.add(videoCommentDTO);
    }

    /**
     * 分页查询评论
     * @param videoCommentQueryDTO
     * @return
     */
    public PageBean commentListPage(VideoCommentQueryDTO videoCommentQueryDTO) {
        //分页查询
        PageHelper.startPage(videoCommentQueryDTO.getPage(),videoCommentQueryDTO.getPageSize());
        Page<VideoCommentVO> page = videoCommentMapper.listPage(videoCommentQueryDTO.getVideoId());
        long total = page.getTotal();
        List<VideoCommentVO> records = page.getResult();
        return new PageBean(total, records);
    }
}
